const mongoose = require('mongoose');
const config = require('../config');

const cfg = {
  ...config,
  id: false,
  strict: false
}

const ToSchema = new mongoose.Schema({
  faction: {
    type: String,
    enum: ['HORDE', 'ALLIANCE'],
  },
  mapID: {
    type: Number,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  target: String,
  npc: String,
  description: {
    type: String,
    required: true,
  },
  position: {
    x: Number,
    y: Number,
  },
});

const NPCSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  description: {
    type: String,
    required: true,
  },
  position: {
    x: Number,
    y: Number,
  },
})

const MapSchema = new mongoose.Schema({
  mapID: Number,
  name: String,
  mapType: Number,
  parentMapID: Number,
  flags: Number,
  description: String,
  npc: NPCSchema,
  faction: {
    type: String,
    enum: ['HORDE', 'ALLIANCE'],
  },
  to: [ToSchema]
}, cfg)

const MapWaySchema = new mongoose.Schema({
  type: {
    type: String,
    enum: ['CLASS', 'TOY', 'ITEM'],
  },
  id: Number,
  name: String,
  professionID: String,
  professionName: String,
  to: [ToSchema]
}, cfg)


exports.Map = mongoose.model('Map', MapSchema, 'map');
exports.MapWay = mongoose.model('MapWay', MapWaySchema, 'map-way');
